package com.neuedu.cockpit.common;

public class Encode
{
    // 转义 下划线和百分号
    public static String encodeStr(String str) {
        if (null != str && (str.contains("_") || str.contains("%"))) {
            char[] chars = str.toCharArray();
            StringBuilder result = new StringBuilder();
            for (char ch : chars) {
                if (ch == '_' || ch == '%') {
                    result.append("\\");
                }
                result.append(ch);
            }
            return result.toString();
        }
        return str;
    }
}
